Skip to content

Reduce WASI compiler memory growth and startup overhead - #170

Closed
vishvananda wants to merge 3 commits into
mainfrom
fix/wasi-heap-growth
Closed

vishvananda wants to merge 3 commits into
mainfrom
fix/wasi-heap-growth

Conversation

@vishvananda

@vishvananda vishvananda commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

WebKit can copy the whole Wasm heap when memory grows without a fast-memory reservation. Many small WASI allocations become expensive. Creating a new compiler instance for every file also loses per-instance browser execution state.

Give the single-threaded WASI host a logical heap break and bounded spare capacity. Grow by 25%, with at most 16 MiB spare. Retry the exact amount needed if that reservation fails. Keep overflow, failure and alignment checks.

The WASI reference export also supplies two leaf assembly functions for reading and restoring the stack pointer, and a function for initializing and reading the logical heap break. The browser can save the initial process image, restore its data and stack between files, and clear only the heap range used by the preceding invocation. Reserved pages are then reused. The helper source is included in the frozen source profile and compiled during self-build. Native source sets stay unchanged apart from an empty translation unit; there is no new student requirement.

The browser reset implementation is in the incpption repository. Older compiler exports and the Emscripten Clang host keep their existing isolation behavior.

Validation:

  • Full strict report: 11,312 tests passed. Harness, debug-info, PA5 self-host, native inception and all architecture, placement, source, file and format audits passed.
  • WASI self-build reproduces all 467 objects and the final compiler. All 934 native/WASI x86 object comparisons at O0/O2 match.
  • The complete native compiler binary is byte-identical to the baseline.
  • A full student export, reference regeneration and its file audit passed.
  • Browser phone WebKit qualification passes both playable comparison outputs, cancellation, all self-build objects and final module, x86 floating-point checks, and valid/invalid compile requests. Self-build took 75.8s with four workers. OpenLara took cppgm8.8s and Clang45.5s with two workers per lane; cppgm retained two workers and peaked at93.7MiB per worker.
  • Runtime tests cover initial data, zeroed reused heap, stack restoration, fresh WASI imports, bounded capacity, trap retirement and fallback for older exports. The heap tests cover contiguous allocation, bounded spare capacity, exact-size retry, allocation failure and overflow.

The browser numbers above are local Linux WebKit measurements with phone emulation, not physical iPhone results. A calibrated comparison and full journey in real Mac Safari are running. Earlier heap-only Mac tests did not establish a speedup; the reusable process host is a separate improvement. The production site continues to use the published0.9.3 seed until a new release exports these helpers.

@vishvananda vishvananda changed the title Reduce WASI heap growth overhead in WebKit Reduce WASI compiler memory growth and startup overhead Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant